/*
 * @Author: yusha
 * @Date: 2023-06-13 15:33:41
 * @LastEditors: yusha
 * @LastEditTime: 2023-07-11 17:06:35
 * @Description: 接口
 */
import axios from 'axios';
import { message } from 'antd';
import { serviceConfig } from './swaggerServiceConfig';

export interface User {
    loginInfo: {
      userId: string;
      username: string;
    };
    userInfo: {};
    auth: never[];
    token: string;
  }
/** 接口前缀 */
const newConfig = { ...serviceConfig };
/** 获取token */
const getUserInLocal = () => {
    const usrStr = window.localStorage.getItem('user');
    if (!usrStr) return;
    try {
        const user = JSON.parse(usrStr).user as User;
        return user;
    } catch (e) {
        return undefined;
    }
};
const axiosOemPurchase = axios.create({
    baseURL: newConfig.baseURL,
    headers: { 'token': getUserInLocal()?.token }
});
    // 请求拦截
// axiosOemPurchase.interceptors.request.use(function (config) {
//     config.headers = config.headers ?? {};
//     const isPost = ['POST', 'post'].includes(config.method!);
//     const token = getUserInLocal()?.token;
//     if (token) {
//         config.headers['X-AuthToken'] = token;
//     }
//     if (isPost) {
//         if (!config.data && config.params) {
//             config.data = config.params;
//         }
//         config.params = {};
//         config.headers['Content-Type'] = 'application/json';
//     }
//     return config;
// });

// 返回拦截
axiosOemPurchase.interceptors.response.use(function (response) {
    if (response.data.code === 200 || response.data.code === '0') return response;
    message.error(response.data.message);
    return Promise.reject(response.data.message);
}, function (error) {
    message.error('请求错误：' + String(error));
    return Promise.reject(error);
});


// /** 异常采购单列表 */
// export const abnormalPurchaseList = (data) => {
//     return axiosOemPurchase({ url: '/purchase/oem/purchase/abnormal/pagePurchase', method: 'POST', data });
// };

// /** 新增付款申请详情 */
// export const addPaymentDetail:any = (params) => {
//     return axiosOemPurchase({ url: '/purchase/payment/request/add', method: 'GET', params });
// };

/** 线上问题登记--新增 */
export const bugRegisterAdd:any = (data) => {
    return axiosOemPurchase({ url: '/test/bugRegister/create', method: 'POST', data });
};

/** 线上问题登记--修改 */
export const bugRegisterEdit:any = (data) => {
    return axiosOemPurchase({ url: '/test/bugRegister/update', method: 'POST', data });
};

/** 线上问题登记--删除 */
export const bugRegisterDelete:any = (data) => {
    return axiosOemPurchase({ url: '/test/bugRegister/delete', method: 'POST', data });
};

/** 线上问题登记--查询翻页 */
export const bugRegisterQryPage:any = (data) => {
    return axiosOemPurchase({ url: '/test/bugRegister/list', method: 'POST', data });
};

/** 线上问题登记--查询详情 */
export const bugRegisterQryInfo = (params) => {
    return axiosOemPurchase({ url: '/test/bugRegister', method: 'GET', params });
};

export const allotNew = (params) => {
    return axiosOemPurchase({ url: '/purchase/allotNew', method: 'GET', params });
};


/** 需求登记--新增 */
export const demandReportAdd:any = (data) => {
    return axiosOemPurchase({ url: '/test/demandReport/create', method: 'POST', data });
};

/** 需求登记--修改 */
export const demandReportEdit:any = (data) => {
    return axiosOemPurchase({ url: '/test/demandReport/update', method: 'POST', data });
};

/** 需求登记--删除 */
export const demandReportDelete:any = (data) => {
    return axiosOemPurchase({ url: '/test/demandReport/delete', method: 'POST', data });
};

/** 需求登记--查询翻页 */
export const demandReportQryPage:any = (data) => {
    return axiosOemPurchase({ url: '/test/demandReport/list', method: 'POST', data });
};

/** 需求登记--获取关联项目 */
export const qryBeeworkProduct:any = (data) => {
    return axiosOemPurchase({ url: '/test/demandReport/qryBeeworkProduct', method: 'POST', data });
};


// 发布计划
/** 发布计划--新增 */
export const publishPlanAdd:any = (data) => {
    return axiosOemPurchase({ url: '/test/publishPlan/create', method: 'POST', data });
};

/** 发布计划--修改 */
export const publishPlanEdit:any = (data) => {
    return axiosOemPurchase({ url: '/test/publishPlan/update', method: 'POST', data });
};

/** 发布计划--删除 */
export const dpublishPlanDelete:any = (data) => {
    return axiosOemPurchase({ url: '/test/publishPlan/delete', method: 'POST', data });
};

/** 发布计划--查询翻页 */
export const publishPlanQryPage:any = (data) => {
    return axiosOemPurchase({ url: '/test/publishPlan/list', method: 'POST', data });
};

export const mobilePhoneList = (data) => {
    return axiosOemPurchase({ url: '/test/mobilePhone/list', method: 'POST', data });
};

export const mobilePhoneAdd = (data) => {
    return axiosOemPurchase({ url: '/test/mobilePhone/create', method: 'POST', data });
}; 

export const mobilePhoneEdit = (data) => {
    return axiosOemPurchase({ url: '/test/mobilePhone/update', method: 'POST', data });
};

export const mobilePhoneOperateLog = (data) => {
    return axiosOemPurchase({ url: '/test/mobilePhoneLog/list', method: 'POST', data });
};

export const platformAddressList = (data) => {
    return axiosOemPurchase({ url: '/test/platformAddress/list', method: 'POST', data });
};  

export const platformAddressAdd = (data) => {
    return axiosOemPurchase({ url: '/test/platformAddress/create', method: 'POST', data });
};

export const platformAddressEdit = (data) => {
    return axiosOemPurchase({ url: '/test/platformAddress/update', method: 'POST', data });
};

export const platformAddressDelete = (data) => {
    return axiosOemPurchase({ url: '/test/platformAddress/delete', method: 'POST', data });
};